package com.management.vtribe.service;

import com.management.vtribe.Bean.User;
import com.management.vtribe.mapper.ArticleMapper;
import com.management.vtribe.mapper.TagMapper;
import com.management.vtribe.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    ArticleMapper articleMapper;

    @Autowired
    TagMapper tagMapper;

    public List<User> getAllUser(){
        return userMapper.getAllUser();
    };

    public List<User> getUserByUsername(String username){
        return userMapper.getUserByUsername(username);
    }

    public List<User> getUserById(int id){
        return userMapper.getUserById(id);
    }

    public int deleteUserById(int id){
        List<Integer> list = articleMapper.selectIdByAuthor(id);
        int[] ids = new int[list.size()];
        for(int i = 0;i<list.size();i++){
            ids[i]=list.get(i);
        }
        articleMapper.deleteArticleContentById(ids);
        articleMapper.deleteArticleByAuthor(id);
        tagMapper.deleteUserTagById(id);
        return userMapper.deleteUserById(id);
    }

    public int updateUserById(String state,int id){
        return userMapper.updateUserById(state,id);
    }
}
